/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilitaire;

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Romain LOUVET
 */
public class GestionSQL {

    private static String url, login, pass;
    private Connection con = null;
    private static GestionSQL GestionSQL;

    private GestionSQL() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {

        Class.forName("org.gjt.mm.mysql.Driver").newInstance();

        con = (Connection) DriverManager.getConnection(url, login, pass);
        GestionSQL = this;


    }

    public static GestionSQL getConnection() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
        if (GestionSQL == null) {
                //url = "jdbc:mysql://192.168.1.190:3307/mobileagri";
                url = "jdbc:mysql://localhost:3307/mobileagri";
                login = "****";
                pass = "****";
            
            GestionSQL c = new GestionSQL();
            return c;
        }
        return GestionSQL;
    }

    public Connection getCon() {
        return con;
    }

    public void fermerConnection(){
        try {
            this.con.close();
        } catch (SQLException ex) {
           utilitaire.Log.getLog().ecrireErreur(ex.getMessage());
        }
    }
}
